<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户资金管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../../../xbr_layui_extend/layui-v2.6.8/css/layui.css">
</head>
<body>
<div class="layui-fluid" style="padding: 15px;">
    <form class="layui-form" action="" lay-filter="form-post" id="userForm" method="post">
        <div class="layui-row">
            <div class="layui-col-xs5">
                <div class="layui-form-item">
                    <label class="layui-form-label">收款人</label>
                    <div class="layui-input-block">
                        <input type="text" name="inAcctName" placeholder="收款人姓名" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs5">
                <div class="layui-form-item">
                    <label class="layui-form-label">查询状态</label>
                    <div class="layui-input-block">
                        <select name="pabTradeStatus" >
                            <option value="">全部记录</option>
                            <option value="create">创建</option>
                            <option value="success">交易成功</option>
                            <option value="fail">交易失败</option>
                            <option value="handle">处理中</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs2">
                <div class="layui-form-item" style="text-align: center">
                    <a class="layui-btn" lay-submit lay-filter="post-btn">查询</a>
                </div>
            </div>
        </div>
    </form>
    <!--表格部分-->
    <table class="layui-hide" id="accTable" lay-filter="accTable"></table>
    <div id="accTablePage"></div>
    <!--隐藏模板 -->
    <script type="text/html" id="bar">
        <a class="layui-btn layui-btn-sm" lay-event="detail">查询</a>
    </script>
</div>

<script src="../../../xbr_layui_extend/layui-v2.6.8/layui.js"></script>
<script>
    layui.extend({
        admin: '/platform/xbr_layui_extend/admin' //集成路径
    }).use(["admin", 'form', 'table', 'laypage'], function () {
        const $ = layui.$, form = layui.form, admin = layui.admin, table = layui.table, laypage = layui.laypage;
        let pabTradeStatus = null, inAcctName = null;
        //加载TABLE
        refTable(1, 10);
        function refTable(page, limit) {
            admin.req({
                url: "/platform/pab/getTradeRecordPage",
                data: {pabTradeStatus: pabTradeStatus,inAcctName:inAcctName, page: page, limit: limit},
                done: function (res) {
                    if (res.data == null) return;
                    table.render({
                        elem: '#accTable',
                        cols: [[ //标题栏
                            {field: 'tradeNo', title: '本地流水号'},
                            {field: 'batchNo', title: '批次单号'},
                            {field: 'outAcctName', title: '付款人名称'},
                            {field: 'inAcctName', title: '收款人名称'},
                            {field: 'tranAmount', title: '交易金额'},
                            {field: 'pabTradeStatus', title: '交易状态', templet: (d) => tradeStatusNames(d.pabTradeStatus)},
                            {fixed: 'right', title: '操作', toolbar: '#bar', width: 78}
                        ]],
                        data: res.data.list,
                        done: function () {
                            table.render();
                            form.render();
                        }
                    });
                    //总页数低于页码总数
                    laypage.render({
                        elem: 'accTablePage',
                        limit: limit,
                        curr: page,
                        limits: [10, 50, 100, 500],
                        count: res.data.total, //数据总数
                        jump: function (obj, first) {
                            if (first) return;
                            refTable(obj.curr, obj.limit)
                        }
                    });
                }
            });
        }

        //监听行工具事件
        table.on('tool(accTable)', function (obj) {
            const data = obj.data;
            if (obj.event === 'detail') {
                layer.open({
                    type: 2,
                    area: ['720px',"560px"],
                    title: "交易查询",
                    content: ['./querySingleTransfer.html'],
                    success:function (layero, index) {
                        const iframe = window['layui-layer-iframe' + index];
                        iframe['child'](data.tradeNo);
                    }
                });
            }
        });

        //交易状态
        function tradeStatusNames(state) {
            return {create: "创建", success: "交易成功", fail: "交易失败", handle: "处理中"}[state];
        }

        //上传完毕 提交表单
        form.render(null, 'form-post');
        form.on('submit(post-btn)', function (data) {
            pabTradeStatus = data.field.pabTradeStatus;
            inAcctName = data.field.inAcctName;
            refTable(1, 10);
            return false;
        });

    });
</script>
</body>
</html>